package cn.ithers.blog.controller.admin;

import cn.ithers.blog.annotion.CheckTooFrequentCommit;
import cn.ithers.blog.response.ResponseResult;
import cn.ithers.blog.service.IWebSiteInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zhanghuan
 * @date: 2020/8/28 14:06
 * @description:
 */
@Api(value = "网站信息", tags = "网站信息")
@RestController
@RequestMapping("/admin/web_size_info")
public class WebSiteInfoAdminApi {

    @Autowired
    private IWebSiteInfoService iWebSiteInfoService;


    /**
     * 获取网站标题title-title
     *
     * @return
     */
    @PreAuthorize("@permission.admin()")
    @ApiOperation("获取网站标题")
    @GetMapping("/title")
    public ResponseResult getWebSizeTitle() {
        return iWebSiteInfoService.getWebSiteTitle();
    }


    /**
     * 修改网站标题
     *
     * @param title
     * @return
     */
    @CheckTooFrequentCommit
    @ApiOperation("修改网站标题")
    @PreAuthorize("@permission.admin()")
    @PutMapping("/title")
    public ResponseResult updateWebSizeTitle(@ApiParam(value = "标题", required = true) @RequestParam("title") String title) {
        return iWebSiteInfoService.putWebSiteTitle(title);
    }


    /**
     * 获取seo信息
     *
     * @return
     */
    @ApiOperation("获取seo信息")
    @PreAuthorize("@permission.admin()")
    @GetMapping("/seo")
    public ResponseResult getSeoInfo() {
        return iWebSiteInfoService.getSeoInfo();
    }

    /**
     * 修改网站seo信息
     *
     * @param keywords
     * @param description
     * @return
     */
    @CheckTooFrequentCommit
    @ApiOperation("修改网站seo信息")
    @PreAuthorize("@permission.admin()")
    @PutMapping("/seo")
    public ResponseResult putSeoInfo(@ApiParam(value = "关键字", required = true) @RequestParam("keywords") String keywords,
                                     @ApiParam(value = "描述", required = true) @RequestParam("description") String description) {
        return iWebSiteInfoService.putSeoInfo(keywords, description);
    }

    /**
     * 获取统计信息view-count
     *
     * @return
     */
    @ApiOperation("获取网站流量")
    @PreAuthorize("@permission.admin()")
    @GetMapping("/view_count")
    public ResponseResult getWebSizeViewCount() {
        return iWebSiteInfoService.getSiteViewCount();
    }
}
